﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Globalization;

using SBPweb.Data.Generic;

namespace SBPweb.Data
{
    /// <summary>
    /// This exception is thrown when a validation error
    /// is detected in the repository or database.
    /// </summary>
    [Serializable]
    public class RepositoryValidationException : RepositoryException
	{

		#region Private members

		private string failedField;
        private string failureReason;

		#endregion

		#region Constructor logic

		/// <summary>
		/// Creates a new RepositoryValidationException instance
		/// </summary>
		/// <param name="failedField">Name of field, wich caused the fail</param>
		/// <param name="failureReason">Reason of failure</param>
        public RepositoryValidationException(string failedField, string failureReason)
            : this( failedField, failureReason, null )
        {
        }

		/// <summary>
		/// Creates a new RepositoryValidationException instance
		/// </summary>
		/// <param name="failedField">Name of field, wich caused the fail</param>
		/// <param name="failureReason">Reason of failure</param>
		/// <param name="inner">InnerException of exception</param>
		public RepositoryValidationException(string failedField, string failureReason, Exception inner)
			: base(string.Format(CultureInfo.CurrentCulture, GenericResources.ValidationFailed, failedField, failureReason), inner)
        {
            this.failedField = failedField;
            this.failureReason = failureReason;
        }

		#region Standard Exception Constructors

		/// <summary>
		/// Initializes a new RepositoryValidationException
		/// </summary>
		public RepositoryValidationException()
			: base()
		{
		}

		/// <summary>
		/// Initializes a new RepositoryValidationException
		/// </summary>
		/// <param name="message">Message of exception</param>
		public RepositoryValidationException(string message)
			: base(message)
		{
		}

		/// <summary>
		/// Initializes a new RepositoryValidationException
		/// </summary>
		/// <param name="message">Message of exception</param>
		/// <param name="inner">InnerException of exception</param>
		public RepositoryValidationException(string message, Exception inner)
			: base(message, inner)
		{
		}

		/// <summary>
		/// Initializes a new RepositoryValidationException
		/// </summary>
		/// <param name="info">info parameter for serialization/deserialization</param>
		/// <param name="context">context parameter for serialization/deserialization</param>
		protected RepositoryValidationException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
		}

		#endregion

		#endregion

		#region Public properties

		/// <summary>
		/// Returns the name of the field, that caused the exception
		/// </summary>
		public string FailedField
        {
            get { return failedField; }
        }

		/// <summary>
		/// Returns the reason of the exception
		/// </summary>
        public string FailureReason
        {
            get { return failureReason; }
		}

		#endregion

    }
}
